# Contributor: Carlo Landmeter <clandmeter@gmail.com>
# Maintainer:
pkgname=opencv
pkgver=3.2.0
pkgrel=6
pkgdesc="Computer vision and machine learning software library"
url="https://opencv.org"
arch="all"
license="BSD-3-Clause"
makedepends="cmake ffmpeg-dev libpng-dev libjpeg-turbo-dev tiff-dev jasper-dev
	libgomp openexr-dev gtk+3.0-dev gtk+-dev gst-plugins-base-dev
	libgphoto2-dev v4l-utils-dev libwebp-dev libdc1394-dev doxygen"
subpackages="$pkgname-dev $pkgname-libs"
source="opencv-$pkgver.tar.gz::https://github.com/opencv/opencv/archive/$pkgver.tar.gz"

prepare() {
	default_prepare
	# purge 3rd party except carotene
	for i in "$builddir"/3rdparty/*; do
		case $i in
		*/carotene*) continue;;
		esac
		rm -rf "$i"
	done
}

build() {
	if [ "$CARCH" != "x86_64" ]; then
		local _sse="-DENABLE_SSE=OFF -DENABLE_SSE2=OFF"
	fi
	cmake \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
		-DCMAKE_C_FLAGS="$CFLAGS" \
		-DENABLE_PRECOMPILED_HEADERS=OFF \
		-DWITH_OPENMP=ON \
		-WITH_OPENCL=ON \
		-DWITH_IPP=OFF \
		$_sse
	make
}

package() {
	make DESTDIR="$pkgdir" install
}

sha512sums="381fc8146722f7eeed5ec6f36a0180f3210a0bc8412f9f9d5d667827241a12709afee6fd42fb6f8b4e0ff4ed96cc645c55590ac89f65c529d4fbb6cd0ee752ed  opencv-3.2.0.tar.gz"
